#!/usr/bin/bash

# [[  sh 执行会报错，bash 执行不报错
# 如果不指定变量名，则会把输入保存到默认变量REPLY中

DELAY=3
while [[ $REPLY != 0 ]]; do
	clear
	cat <<-EOF
		Please select:
		1. Display System Information
		2. Display Disk Space
		3. Display Home Space Utilization
		0. Quit
	EOF

	read -p "Enter selection[0-3]> "
	if [[ $REPLY =~ ^[0-3]$ ]]; then
		case $REPLY in
		1)
			echo "Hostname: $HOSTNAME "
			uptime
			sleep $DELAY
			;;
		2)
			df -h
			sleep $DELAY
			;;
		3)
			if [ $(id -u) -eq 0 ]; then
				echo "Home Space Utilization (All Users)"
				du -sh /home/*
			else
				echo "Home Space Utilization ($USER)"
				du -sh "$HOME"
			fi
			sleep $DELAY
			;;
		esac
	else
		echo "Invalid entry."
		sleep $DELAY
	fi
done
echo "Program terminated."
